package com.nbsaas.boot.product.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.rest.enums.StoreState;
import com.nbsaas.boot.rest.filter.Operator;
import lombok.Data;

import javax.persistence.*;


@CreateByUser
@ComposeView
@Data
@FormAnnotation(title = "产品管理", model = "产品", menu = "1,57,59")
@Entity
@Table(name = "bs_product")
public class Product extends AbstractEntity {

    @SearchItem(label = "产品名称", name = "name")
    @FormField(title = "名称", sortNum = "2", grid = true, width = "200", col = 22, required = true)
    private String name;


    @FormField(title = "图片", sortNum = "2", grid = true, col = 22, type = InputType.image)
    private String logo;

    @FormField(title = "产品分类", sortNum = "2", grid = true, col = 22, type = InputType.select, option = "productCatalog")
    @SearchItem(label = "分类", name = "productCatalog", key = "productCatalog.id", operator = Operator.eq, type = InputType.select, classType = Long.class)
    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private ProductCatalog productCatalog;

    @FormField(title = "简单介绍", sortNum = "2", grid = true, col = 22)
    private String introduce;


    @FormField(title = "在线地址", sortNum = "2", col = 22)
    private String url;

    @FormField(title = "排序号", sortNum = "2", grid = true, col = 22, sort = true, type = InputType.el_input_number)
    private Integer sortNum;

    @FormField(title = "创建人", sortNum = "2", col = 22, grid = true, ignore = true)
    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private User creator;

    @FormField(title = "详细介绍", sortNum = "2", type = InputType.richText, col = 22)
    private String note;

    @SearchItem(label = "状态", name = "storeState", operator = Operator.eq, show = false)
    private StoreState storeState;


}
